package com.isay.app.honey.ui.direct;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.isay.app.honey.R;
import com.isay.app.honey.ui.invite.InviteActivity;


/**
 * Created by cywu4 on 2018/12/27.
 */
public class DirectDialog extends Dialog implements View.OnClickListener {


    private MDialogListener mDialogListener;

    private TextView mTvContent;
    private TextView mTvBtn;
    private ImageView mIv;

    //完成了邀请10人
    private boolean isCompleted = false;
    private Context mContext;

    public interface MDialogListener {
        void onSure();
    }

    public void setListener(MDialogListener l) {
        mDialogListener = l;
    }

    public void setShowText(boolean isComplete, String tips) {
        isCompleted = isComplete;
        if (tips == null) {
            tips = "";
        }
        mTvContent.setText(tips);
        if (isComplete) {
            mTvBtn.setText("我知道了");
            mIv.setVisibility(View.GONE);
            mIv.setBackgroundResource(R.drawable.iv_dialog_jiesuo);
        } else {
            mTvBtn.setText("立即邀请好友");
            mIv.setVisibility(View.VISIBLE);
            mIv.setBackgroundResource(R.drawable.iv_dialog_xinfeng);
        }
    }

    public DirectDialog(Context context) {
        super(context, R.style.AlertDlgStyle);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        mContext = context;
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_view_direct, null);
        view.findViewById(R.id.iv_d_close).setOnClickListener(this);
        view.findViewById(R.id.tv_sure).setOnClickListener(this);
        mIv = view.findViewById(R.id.iv_d_xinfeng);
        mTvContent = view.findViewById(R.id.tv_content);
        mTvBtn = view.findViewById(R.id.tv_sure);
        setContentView(view);
        setCancelable(false);
    }


    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.iv_d_close) {
            dismiss();
        } else if (id == R.id.tv_sure) {
            if (mDialogListener != null) {
                mDialogListener.onSure();
            }
            if (!isCompleted && mContext instanceof Activity) {
                InviteActivity.launch(mContext);
            }
            dismiss();
        }

    }
}
